<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
	<head>
		<title>合作伙伴信息修改</title>		   
		<link href="../../../css/Public.css" type="text/css" rel="stylesheet" />
		<link href="../../../css/PublicEdit.css" type="text/css" rel="stylesheet" />	
		<script>		
		//普通座机号：+0086-010-66668888   
		function isTel(s)     
		{     
		    var patrn = /^[+]{0,1}(\d){1,4}[ ]{0,1}([-]{0,1}((\d)|[ ]){1,12})+$/;   
		    if(!patrn.exec(s)) {   
		        return false;   
		    }   
		    return true;   
		}   	
		//必需是大于0的整数
		function isInt(str){
			//var reg = /^(-|\+)?\d+$/ ;
			var reg = /^[1-9]\d*$/;	
			return reg.test(str);			
		}
		function isUrl(str)
		{
			var reg=/^[a-zA-z]+:\/\/[^\s]*$/;
			return reg.test(str);				
		}	
		//验证数据  提示内容的长度
		 function GetLength(value) {
		        var _tmp = value;
		        var _length = 0;
		        for (var i = 0; i < _tmp.length; i++) {
		            if (_tmp.charCodeAt(i) > 255) {
		                _length = _length + 2;
		            }
		            else {
		                _length++;
		            }
		        }
		        return _length;
		}	
		function IntiData()
		{
			 var provincelist= window.document.getElementById("partnerinfo_provinceid").value;	
			 //alert(provincelist);			 
					 var chks=document.getElementsByTagName("input");				    	   
				     for (i = 0; i < chks.length; i++) 
				     {
				        var cur=chks[i];
				        if(cur.type=="checkbox")
				            {  
						            var pvalue=","+cur.value+",";
						           // alert(pvalue);
						            if(provincelist.indexOf(pvalue)>=0)
						            {
						           		window.document.getElementById(cur.id).checked=true;// cur.checked==true;
						            }					           
					        }		          
				    }
		}
		function checkAllData()
		{		
					var oValue=document.getElementById("partnerinfo_username").value;
				    if(oValue!=null && oValue!="")
				    {
				        var pattern=/^(?!_)(?!.*?_$)[a-zA-Z0-9_\u4e00-\u9fa5]{5,19}$/;
				        if(!pattern.test(oValue))				       
				        {
				              alert("用户名只允许汉字,字母,数字,下划线组成的长度为5~20个字符!");				              
				              //document.getElementById("partnerinfo_username").value='';   
							  document.getElementById("partnerinfo_username").focus(); 
				        	  window.event.returnValue = false;
							 return;
				        }
				    }
				    else
				    {
				         alert("用户名不能为空!"); 
						   document.getElementById("partnerinfo_username").focus();  
				         window.event.returnValue = false;
						return;
				    }
		 				var password = document.getElementById("partnerinfo_password").value;    
						if (password.match("^[a-zA-Z0-9_]{5,20}$") == null)
							{
								 	alert("密码由数字字母组成的5-20位字符");
							 		 document.getElementById("partnerinfo_password").value=''; 
								   document.getElementById("partnerinfo_password2").value='';   
								   document.getElementById("partnerinfo_password").focus();  
							   		window.event.returnValue = false;
				            		return;
							} 						
						 var u1=window.document.getElementById("partnerinfo_partnername").value;
						 var upid=window.document.getElementById("partnerinfo_partnerid").value;
						  if(u1!=null && u1!="")
				       	 {
				       	 	if(GetLength(u1)>50)
							  	{
							  		 alert("公司名称长度不能超过50！");
								     document.getElementById("partnerinfo_partnername").focus();        
								    window.event.returnValue = false;
					            	return;
							  	}
					       		<c:forEach var="blist" items="${Partnerinfolist}">	
					         	if(u1=="${blist.partnername}"&&upid!="${blist.partnerid}")
					 			 {
					     			 alert("该公司已经存在！");
					     			 window.event.returnValue = false;
						  			return;
							  	}		  
			      			 	 </c:forEach> 
				        }
				        else
				        {            
				            alert("公司名称不能为空!");
				            window.event.returnValue = false;
				            return;
				        }		   
				        
		         
				       
			      	var partnerinfo_siteurl= window.document.getElementById("partnerinfo_siteurl").value;
					 if(partnerinfo_siteurl!=null && partnerinfo_siteurl!="")
			        {
			       		 if(!isUrl(partnerinfo_siteurl)||partnerinfo_siteurl.length>100)   
			             { 			                   
			                   alert("公司网址格式不正确或长度超过100！");  
			                   document.getElementById("partnerinfo_siteurl").focus();                
			                   window.event.returnValue = false;
			                   return;
			             }  
			        }
			        else
			        {            
			            alert("公司网址不能为空!");
			            window.event.returnValue = false;
			            return;
			        }	
			         if(GetLength(window.document.getElementById("partnerinfo_remark").value)>1000)
							  	{
							  		 alert("公司简介长度不能超过1000！");
								     document.getElementById("partnerinfo_linkman").focus();        
								    window.event.returnValue = false;
					            	return;
							  	}		                  
			    	 var partnerinfo_linkman = document.getElementById("partnerinfo_linkman").value;    
						if(partnerinfo_linkman.length==0){
							  alert("联系人不得为空");
							   document.getElementById("partnerinfo_linkman").value='';   
							   document.getElementById("partnerinfo_linkman").focus();        
							    window.event.returnValue = false;
				            	return;
							  }
							   else
							  {
							  	if(GetLength(partnerinfo_linkman)>30)
							  	{
							  		 alert("联系人长度不能超过30！");
								     document.getElementById("partnerinfo_linkman").focus();        
								    window.event.returnValue = false;
					            	return;
							  	}
							  }
							    var partnerinfo_telphone= document.getElementById("partnerinfo_telphone").value; 
							   if(partnerinfo_telphone.length>0)
							   {
							   		if(!isTel(partnerinfo_telphone))
							   		{
							   		 alert("座机格式不对！");
						   		//document.getElementById("partnerinfo_telphone").value='';   
						  			 document.getElementById("partnerinfo_telphone").focus();        
						   			 window.event.returnValue = false;
				           			 return;
							   		}
							   }
							   	if(GetLength(partnerinfo_telphone)>20)
							  	{
							  		 alert("座机长度不能超过20！");
								     document.getElementById("partnerinfo_telphone").focus();        
								    window.event.returnValue = false;
					            	return;
							  	}
					var mobile = document.getElementById("partnerinfo_mobilephone").value;    
						  if(mobile.match("^[0-9_]{11}$") == null){
						 	 alert("手机号码不得为空且为11位数字");
						   		document.getElementById("partnerinfo_mobilephone").value='';   
						  	 document.getElementById("partnerinfo_mobilephone").focus();        
						    window.event.returnValue = false;
				            return;
						  }
					var email = document.getElementById("partnerinfo_email").value;    
						  if(email.length==0||email.match("[a-zA-Z0-9][a-zA-Z0-9._-]*@([a-zA-Z0-9-_]+\\.)+(com|gov|net|com\\.cn|edu\\.cn)$") == null)
						  { 
							  alert("email为空或者格式有误");
							   document.getElementById("partnerinfo_email").value='';   
							   document.getElementById("partnerinfo_email").focus();        
							    window.event.returnValue = false;
					            return;
						  }
						  	if(GetLength(partnerinfo_telphone)>80)
							  	{
							  		 alert("电子邮件长度不能超过80！");
								     document.getElementById("partnerinfo_telphone").focus();        
								    window.event.returnValue = false;
					            	return;
							  	}
					var partnerinfo_address = document.getElementById("partnerinfo_address").value;    
							  if(partnerinfo_address.length==0){
								  alert("通讯地址不得为空");
								   document.getElementById("partnerinfo_address").value='';   
								   document.getElementById("partnerinfo_address").focus();        
								    window.event.returnValue = false;
				           			 return;
							  }            
							  else if(GetLength(partnerinfo_address)>100)
							  	{
							  		 alert("通讯地址长度不能超过100！");
								     document.getElementById("partnerinfo_address").focus();        
								    window.event.returnValue = false;
					            	return;
							  	}
			       // var partnerinfo_provinceid= window.document.getElementById("partnerinfo_provinceid").value;
			         var provincelist="";				 
					 var chks=document.getElementsByTagName("input");
				     var len=chks.length;		   
				     for (i = 0; i < len; i++) 
				     {
				        var cur=chks[i];
				        if(cur.type=="checkbox")
				            {  
					            if(cur.checked==true)
					            {
					            	if(cur.value=="0")
					            	{
					            		provincelist="0,";
					            		break;
					            	}
					            	provincelist =provincelist+cur.value+",";						            		            	
					            }
					        }		          
				    }
				    if(provincelist.length>0)
				    {
				    	 window.document.getElementById("partnerinfo_provinceid").value=","+provincelist;
				    	 //alert(window.document.getElementById("partnerinfo_provinceid").value);
				    }
				    else
				    {
				     		alert("请选择合作省份!");
				             window.event.returnValue = false;
				             return;
				    }
		}
</script>
	</head>
	<body marginheight="0" onload="IntiData()">
		<form action="EditStatusInfo" method="post">
			<input type="hidden" name="partnerinfo.partnerid" id="partnerinfo_partnerid" value="${partnerinfo.partnerid}">	
              
			<div class="l_f_top">
				<div class="l_f_top_left_div">
					<img alt="" src="images/tb.gif" width="16" height="16" />
				</div>
				<div class="l_f_top_right_div">
					信息修改
				</div>
			</div>
			<div class="l_f_body">
				<div class="l_f_body_row">
						<div class="l_f_body_div1">
							用户名：
						</div>
						<div class="l_f_body_div5">
							<input type="text"  style="width: 150px" name="partnerinfo.username" id="partnerinfo_username" value="${partnerinfo.username}">							
						</div>
					</div>
					<div class="l_f_body_row">
						<div class="l_f_body_div1">
							密码：
						</div>
						<div class="l_f_body_div5">
							<input type="password" style="width: 150px"  name="partnerinfo.password" id="partnerinfo_password" value="${partnerinfo.password}">							
						</div>
					</div>	
				<div class="l_f_body_row">
						<div class="l_f_body_div1">
							公司名称：
						</div>
						<div class="l_f_body_div5">
							<input type="text" style="width: 150px"  name="partnerinfo.partnername" id="partnerinfo_partnername" value="${partnerinfo.partnername}">
						</div>
					</div>
					<div class="l_f_body_row">
						<div class="l_f_body_div1">
							公司网址：
						</div>
						<div class="l_f_body_div5">
							<input type="text" style="width: 150px"  name="partnerinfo.siteurl" id="partnerinfo_siteurl" value="${partnerinfo.siteurl}">	</div>
					</div>
				<div class="l_f_body_row">
						<div class="l_f_body_div1">
							公司简介:
						</div>
						<div class="l_f_body_div5">
							<textarea name="partnerinfo.remark" id="partnerinfo_remark" rows="10" style="width: 500px" >${partnerinfo.remark}</textarea>
						</div>
					</div>
					<div class="l_f_body_row" >
						<div class="l_f_body_div1">
							联系人：
						</div>
						<div class="l_f_body_div5">
							<input type="text"  style="width: 150px" name="partnerinfo.linkman" id="partnerinfo_linkman" value="${partnerinfo.linkman}">
						</div>
					</div>
					<div class="l_f_body_row">
						<div class="l_f_body_div1">
							座机：
						</div>
						<div class="l_f_body_div5">
							<input type="text" style="width: 150px"  name="partnerinfo.telphone" id="partnerinfo_telphone" value="${partnerinfo.telphone}">
						</div>
					</div>
					<div class="l_f_body_row">
						<div class="l_f_body_div1">
							手机：
						</div>
						<div class="l_f_body_div5">
							<input type="text" style="width: 150px"  name="partnerinfo.mobilephone" id="partnerinfo_mobilephone" value="${partnerinfo.mobilephone}">							
						</div>
					</div>
					<div class="l_f_body_row">
						<div class="l_f_body_div1">
							电子邮件：
						</div>
						<div class="l_f_body_div5">
							<input type="text" style="width: 150px"  name="partnerinfo.email" id="partnerinfo_email" value="${partnerinfo.email}">						
						</div>
					</div>
					<div class="l_f_body_row">
						<div class="l_f_body_div1">
							通讯地址：
						</div>
						<div class="l_f_body_div5">
							<input type="text" style="width: 500px"  name="partnerinfo.address" id="partnerinfo_address" value="${partnerinfo.address}">
						</div>
					</div>
				<div class="l_f_body_row">
					<div class="l_f_body_div1">
						合作方式:
					</div>
					<div class="l_f_body_div5">
					<select  name="partnerinfo.partnertype" 
							id="partnerinfo_partnertype"   style="width: 150px"  >	
							 <c:if test="${partnerinfo.partnertype==1}"><option value="1" selected>广告</option><option value="2"  >搜索</option></c:if>
		          			 <c:if test="${partnerinfo.partnertype==2}"><option value="1">广告</option><option value="2"  selected>搜索</option></c:if>
						</select>						
					</div>
				</div>
				<div class="l_f_body_row">
					<div class="l_f_body_div1">
						合作省份:
					</div>
					<div class="l_f_body_div5">		
					<input type="checkbox"  value="0" id="Allprovince">全国			
						<c:forEach items="${provincelist}" var="blist">
										<input  type="checkbox"  value="${blist.PId}" id="${blist.PId}">${blist.provincename}
						</c:forEach>
						<input  type="hidden" name="partnerinfo.provinceid" id="partnerinfo_provinceid" value="${partnerinfo.provinceid}">
			    	</div>					
				</div>
							
				
				
						<div class="l_f_body_row">
									<div class="l_f_body_div1">
										审核状态:
									</div>
									<div class="l_f_body_div5">
											<select  name="partnerinfo.checkstatus" 
													id="partnerinfo_checkstatus"   style="width: 150px"  >	
													 <c:if test="${partnerinfo.checkstatus==-1}"><option value="-1" selected>不通过</option><option value="0"  >审核中</option><option value="1" >通过</option><option value="2" >开通</option><option value="3" >暂停</option></c:if>
								          			  <c:if test="${partnerinfo.checkstatus==0}"><option value="-1" >不通过</option><option value="0"  selected>审核中</option><option value="1" >通过</option><option value="2" >开通</option><option value="3" >暂停</option></c:if>
								          			 <c:if test="${partnerinfo.checkstatus==1}"><option value="-1" >不通过</option><option value="0"  >审核中</option><option value="1" selected>通过</option><option value="2" >开通</option><option value="3" >暂停</option></c:if>
								          			 <c:if test="${partnerinfo.checkstatus==2}"><option value="-1" >不通过</option><option value="0"  >审核中</option><option value="1" >通过</option><option value="2" selected>开通</option><option value="3" >暂停</option></c:if>
								          			 <c:if test="${partnerinfo.checkstatus==3}"><option value="-1" >不通过</option><option value="0"  >审核中</option><option value="1" >通过</option><option value="2" >开通</option><option value="3" selected>暂停</option></c:if>
								          	</select>						
									</div>
						</div>
						<div class="l_f_body_row">
									<div class="l_f_body_div1">
										启用状态:
									</div>
									<div class="l_f_body_div5">
											<select  name="partnerinfo.status" 
													id="partnerinfo_status"   style="width: 150px"  >	
													 <c:if test="${partnerinfo.status==1}"><option value="0"  >不可用</option><option value="1" selected>可用</option></c:if>
								          			  <c:if test="${partnerinfo.status==0}"><option value="0"  selected>不可用</option><option value="1" >可用</option></c:if>
								          </select>						
									</div>
						</div>
			</div>
				<div align="center" class="l_f_body_foot">
				   <input type="submit" id="button" name="button" class="button2_60" onclick="checkAllData();"  value="修改"/>		                      
		       	</div>
			
		</form>
	</body>
</html>
